<?php
include('insert_advert.php');
/**
 * Created by PhpStorm.
 * User: tsa
 * Date: 17/12/2013
 * Time: 11:34 πμ
 */
if ($_POST['click'] == "1")
{
    //$sql_q = '" INSERT INTO `field` (`id`,`name`,`divname`,`parent_id`) VALUES (NULL,\''.$_POST['name'].'\',\''.$_POST['divname'].'\','.intval($_POST['parent_id']).') "';
    $sql_q = 'INSERT INTO field (`id`,`name`,`divname`,`parent_id`,`menu_id`) VALUES (NULL,"'.$_POST['name'].'","'.$_POST['divname'].'",'.intval($_POST['parent_id']).','.intval($_POST['menu_id']).')';
    $result = mysqli_query($con, $sql_q);
    echo $sql_q;
}

$click = "0";
$_POST["click"] = "0";
$result = mysqli_query($con, " SELECT * FROM field group by name ");
$form = '<h4>insert field</h4>';
$form = $form . '<form id="form_insert_fields" method="post">';
$form = $form . '<label> Name</label>';
$form = $form . '<input name="name" type="text" value=""/>';
$form = $form . '<label> Divname</label>';
$form = $form . '<input name="divname" type="text" value=""/>';
$form = $form . '<label> Parent_id</label>';
$form = $form . '<select name="parent_id"/>';
$form = $form . '<option value="0" selected="selected"</option>';
while($row = mysqli_fetch_array($result))
{
    $form = $form . '<option value="'.$row['id'].'">'.$row['name'].'</option>';
}
$form = $form . '</select>';
$form = $form . '<label> menu_id</label>';
$form = $form . '<select name="menu_id"/>';
$form = $form . '<option value="0" selected="selected"</option>';
$result = mysqli_query($con, " SELECT * FROM menu group by name ");
while($row = mysqli_fetch_array($result))
{
    $form = $form . '<option value="'.$row['id'].'">'.$row['name'].'</option>';
}
$form = $form . '<option value="-1">Όλα</option>';
$form = $form . '</select>';
$form = $form . '<input name="click" type="hidden" value="1"/>';
$form = $form . '<input type="submit" value="Add field"/>';
$form = $form . '</form>';
echo $form;
?>